import mysql.connector

# 配置数据库连接信息
config = {
    'user': 'root',
    'password': 'ys_nj_sst!',
    'host': '127.0.0.1',
    'database': 'new_ys_wms',
    'raise_on_warnings': True
}

# 创建连接
conn = mysql.connector.connect(**config)

# 创建cursor对象
cursor = conn.cursor()

# 执行查询
cursor.execute("SELECT * FROM t_unint")

# 获取查询结果
for row in cursor:
    print(row)


# 新增
insert_query = 'insert into t_unint(unit, create_time) values (%s, %s)'
data = ('测试', '2025-04-23 17:04:52')
cursor.execute(insert_query, data)
conn.commit()

# 更新
update_query = 'update t_unint set unit = %s where unit = %s'
data = ('测试1', '测试')
cursor.execute(update_query, data)
conn.commit()

# 删除
delete_query = 'delete from t_unint where unit = %s'
data = ('测试1',)
cursor.execute(delete_query, data)
conn.commit()

# 关闭cursor和连接
cursor.close()
conn.close()
